{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "86b73f3b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-31T11:09:21.858061Z",
     "start_time": "2022-01-31T11:09:21.852729Z"
    }
   },
   "outputs": [],
   "source": [
    "# !pip install spinesTS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "236ec2bf",
   "metadata": {},
   "source": [
    "# Preprocessing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6a032a4d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-31T11:09:24.894716Z",
     "start_time": "2022-01-31T11:09:23.336286Z"
    }
   },
   "outputs": [],
   "source": [
    "from spinesTS.preprocessing import GaussRankScaler, split_series, train_test_split_ts\n",
    "from spinesTS.datasets import DataGenerator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "71f23615",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-31T11:09:28.071993Z",
     "start_time": "2022-01-31T11:09:27.961673Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   0.82418808,    1.30415409,    2.4776221 ,    3.38667017,\n",
       "           2.81494872],\n",
       "       [   2.70545145,    2.72447971,    1.78071865,    2.4212918 ,\n",
       "           1.63484863],\n",
       "       [   2.24371862,    1.31270677,    2.29092902,    1.55401096,\n",
       "           1.25527834],\n",
       "       ...,\n",
       "       [-341.88788684, -342.12667668, -340.81181353, -340.3256502 ,\n",
       "        -339.13887157],\n",
       "       [-338.11322434, -336.66018613, -335.90400323, -334.48370919,\n",
       "        -336.352143  ],\n",
       "       [-337.68784764, -337.63938029, -338.09002676, -338.21170054,\n",
       "        -337.27461899]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = DataGenerator.random_walk(size=100000, random_state=666, started_zero=False).data.reshape(-1, 5)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "da3e6624",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-31T11:09:29.074996Z",
     "start_time": "2022-01-31T11:09:29.071215Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((14000, 4), (6000, 4), (14000,), (6000,))"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split_ts(data[:, :-1], data[:, -1], test_size=0.3)\n",
    "X_train.shape, X_test.shape, y_train.shape, y_test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d718e99b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-31T11:09:36.057477Z",
     "start_time": "2022-01-31T11:09:29.923786Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((14000, 4), (6000, 4), (14000,), (6000,))"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gr = GaussRankScaler(n_jobs=-1)\n",
    "X_train_gr = gr.fit_transform(X_train)\n",
    "X_test_gr = gr.transform(X_test)\n",
    "X_train_gr.shape, X_test_gr.shape, y_train.shape, y_test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e1852b4c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-31T11:09:37.691776Z",
     "start_time": "2022-01-31T11:09:37.402271Z"
    }
   },
   "outputs": [],
   "source": [
    "X_train, X_test, y_train, y_test = split_series(data[:, :-1], data[:, -1], train_size=0.7, window_size=30, \n",
    "                                               pred_steps=30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bc7d8681",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-31T11:09:38.500326Z",
     "start_time": "2022-01-31T11:09:38.497208Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((13958, 30, 4), (5983, 30, 4), (13958, 30), (5983, 30))"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train.shape, X_test.shape, y_train.shape, y_test.shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
